<?php require admin_tpl('header');?>

<div class="tab">
	<ul>
		<?php if ( check_perm('blog','post') ) { ?>
		<li><a href="?mod=blog&ac=write" class="on">撰写文章</a></li>
		<?php } ?>
		<li><a href="?mod=blog&ac=list">文章列表</a></li>
		<?php if ( check_perm('blog','addcate') ||  check_perm('blog','editcate') ||  check_perm('blog','delcate')) {?>
		<li><a href="?mod=blog&ac=category">文章分类</a></li>
		<?php } ?>
		<?php if ( is_founder() ) { ?>
		<li><a href="?mod=blog&ac=blogmeta">自定义域</a></li>
		<?php }?>
	</ul>
</div>

<form name="post" id="post" method="post" action="?mod=blog&ac=write" onsubmit="return check_write()">
<input type="hidden" name="dosubmit" value="yes" />
<input type="hidden" name="type" value="blog" />
<input type="hidden" name="id" value="<?php echo $blog['id']?>" />
	
<div class="main">

<table width="100%">
	<tr valign="top">
		<td id="main_left">
		<table width="100%">
			<tr>
				<td align="right" style="min-width: 40px;">标题：</td>
				<td>
				<input type="text" name="title" class="input" size="70" value="<?php echo $blog['title']?>" onfocus="if(this.value=='未命名文章')this.value=''" />
				<select name="cateid">
					<?php echo cate_options('blog',$blog['cateid']);?>
				</select>
				</td>
			</tr>
			<tr>
				<td valign="top" align="right">内容：</td>
				<td><textarea id="content" name="content" rows="25" style="width: 100%" class="eCotnent"><?php echo $blog['content']?></textarea></td>
			</tr>
			<?php if ( is_admin() || check_perm('blog','upload') ) { ?>
			<tr>
				<td valign="top" align="right">附件：</td>
				<td><iframe src="?mod=upload&ac=upload&postid=<?php echo $blog['id']?>" width="100%" height="100" id="upload" name="upload" frameborder="0" scrolling="auto" ></iframe></td>
			</tr>
			<?php } ?>
			<tr>
				<td valign="top" align="right">摘要：</td>
				<td><textarea id="excerpt" name="excerpt" rows="5" cols="80" style="width: 100%" class="eExcerpt"><?php echo $blog['excerpt']?></textarea></td>
			</tr>
			
			<?php if ( $_CACHE['blogmeta'] ) { ?>
			<?php 
				foreach ( $_CACHE['blogmeta'] as $meta ) { 
					$value = $id ? $blog[$meta['name']]['value'] : $meta['default'];
			?>
			<tr>
				<td valign="top" align="right"><?php echo $meta['name'];?>：</td>
				<td>
				<?php
				if ( $meta['type'] == 'input' ) {
					echo '<input type="input" name="metas['.$meta['name'].']" value="'.$value.'" style="width:100%;" />';
				} elseif ( $meta['type'] == 'textarea' ) {
					echo '<textarea name="metas['.$meta['name'].']"  style="width:100%;height:40px;">'.$value.'</textarea>';	
				}
				?>
				</td>
			</tr>
			<?php } ?>
			<?php } ?>
			<tr>
			<td></td><td>
				<input type="submit" class="button" value="发布文章" />
				<input type="button" class="button" value="另存为草稿" onclick="save_to_draft()" />
				<input type="button" class="button" value="返回上一页" onclick="history.back()" />
			</td>
			</tr>
		</table>
		</td>

		<td id="mid_btn" class="btn_open_out" title="close" width="5">&nbsp;</td>
		
		<!--sidebar-->
		<td id="main_right" width="290">
			<div class="panel">
				<div class="title">高级选项</div>
				<div class="body">
				<p>时间：
				<input type="text" name="year"  style="width:40px" maxlength="4" value="<?php echo $datetime['year']?>">年
				<input type="text" name="month" style="width:23px" maxlength="2" value="<?php echo $datetime['mon']?>">月
				<input type="text" name="day" style="width:23px" maxlength="2" value="<?php echo $datetime['mday']?>">日
				<input type="text" name="hour" style="width:23px" maxlength="2" value="<?php echo $datetime['hours']?>">时
				<input type="text" name="minute" style="width:23px" maxlength="2" value="<?php echo $datetime['minutes']?>">分
				</p>
				<p><input type="checkbox" class="checkbox" name="commentstatus" id="commentstatus" value="1" <?php if ($blog['commentstatus']==1) {echo 'checked';} ?> /><label for="commentstatus">这篇文章允许评论</label></p>
				</div>
			</div>

			<div class="panel">
				<div class="title">文章标签</div>
				<div class="body">
				<p>
				<input type="text" class="input" name="tags" id="tags" style="width:90%" value="<?php echo $blog['tags']?>" /><br />
				<em>多个标签使用英文逗号","分隔</em>
				</p>
				<fieldset id="hot_tags">
					<legend>热门标签</legend>
					<div class="tags">
					<?php echo $hottags; ?>
					</div>
				</fieldset>
				</div>
			</div>

			<div class="panel">
				<div class="title">文章别名</div>
				<div class="body">
				<p><input type="text" name="alias" style="width:90%" value="<?php echo $blog['alias']?>" onkeyup="this.value=this.value.replace(/[^a-z0-9\-_.]/ig,'')" onblur="check_urlname()" /></p>
				<em>由字母、数字、下划线、减号、小数点组成</em>
				</div>
			</div>

			<div class="panel">
				<div class="title">文章访问密码</div>
				<div class="body">
				<p><input type="text" name="password" style="width:90%" maxlength="15" value="<?php echo $blog['password']?>" /></p>
				<em>15个字符以内</em>
				</div>
			</div>
		</td>
		<!--end sidebar-->
	<tr>
</table>

</div>

</form>

<script type="text/javascript" src="script/tinymce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
	mode : "textareas",
	theme : "advanced",
	language : "zh",
	plugins : "emotions,inlinepopups,media,paste,fullscreen,syntaxhl",
	extended_valid_elements : "pre[name|class]",
	editor_selector : "eCotnent",
	content_css : "admin/css/editor.css",
});
tinyMCE.init({
	mode : "textareas",
	theme : "simple",
	language : "zh",
	editor_selector : "eExcerpt"
});
$(function() {
	$('#hot_tags a').each(function(){
		$(this).click(function() {
			if ($(this).attr('class') == 'on') {
				$('#tags').val($('#tags').val().replace($(this).text() + ',',''));
				$(this).removeClass('on')
			} else {
				$('#tags').val($('#tags').val() + $(this).text() + ',');
				$(this).addClass('on');
			}
		});
	});
	$('#mid_btn').hover(function() {$(this).attr('title')=='close' ? $(this).attr('class','btn_open_hover') : $(this).attr('class','btn_close_hover')},function() {$(this).attr('title')=='close' ? $(this).attr('class','btn_open_out') : $(this).attr('class','btn_close_out')}
	);
	$('#mid_btn').click(function(){$('#main_right').toggle();$(this).attr('title') == 'open' ? $(this).attr('title','close') : $(this).attr('title','open');});
});
set_tags_on();
</script>

<?php require admin_tpl('footer');?>